<template>
	<view>
		<view class="formList">
			<u--form labelPosition="left" :model="model" labelWidth="80px" ref="form">
				<u-form-item :label="$t('public.partSpec')+$t('public.colon')" prop="partSpec" borderBottom>
					<u-input v-model="model.partSpec" :placeholder="$t('public.pleaseInput')+$t('public.partSpec')" @confirm="hide()" clearable border="none">
					</u-input>
					<u-icon slot="right" name="scan" @click="scanSpec"></u-icon>
				</u-form-item>
				<u-form-item :label="$t('public.partName')+$t('public.colon')" prop="partName" borderBottom>
					<u-input v-model="model.partName" :placeholder="$t('public.pleaseInput')+$t('public.partName')" @confirm="hide()" clearable border="none">
					</u-input>
					<u-icon slot="right" name="scan" @click="scanName"></u-icon>
				</u-form-item>
				<u-form-item :label="$t('public.partCode')+$t('public.colon')" prop="partCode">
					<u-input v-model="model.partCode" :placeholder="$t('public.pleaseInput')+$t('public.partCode')" @confirm="hide()" clearable border="none">
					</u-input>
					<u-icon slot="right" name="scan" @click="scanCode"></u-icon>
				</u-form-item>
			</u--form>
		</view>
		<!-- 底部按钮 -->
		<bottomBtn fixed :leftText="$t('public.reset')" :rightText="$t('public.search')" @rightBtn="submitBtn" @leftBtn="resetBtn">
		</bottomBtn>
	</view>
</template>
<script>
	import {
		queryPageMap
	} from "@/api/homepage.js"
	import bottomBtn from "@/components/bottomBtn/index.vue"
	export default {
		components: {
			bottomBtn
		},
		data() {
			return {
				model: {
					partName: '',
					partCode: '',
					partSpec: '',
				},
			}
		},
		onPullDownRefresh() {
			setTimeout(function() {
				uni.redirectTo({
					url: "/pages/HomePage/StoreManagement/AccessoryManagement/CheckStorage/index"
				})
				uni.stopPullDownRefresh();
			}, 1000);
		},
		methods: {
			//二维码扫描
			async scanSpec() {
				uni.scanCode({
					success: res => {
						this.model.partSpec = res.result;
					}
				});
			},
			async scanName() {
				uni.scanCode({
					success: res => {
						this.model.partName = res.result;
					}
				});
			},
			async scanCode() {
				uni.scanCode({
					success: res => {
						this.model.partCode = res.result;
					}
				});
			},
			//隐藏键盘
			hide() {
				uni.hideKeyboard()
			},
			//重置
			resetBtn() {
				const validateList = ['model.partName', 'model.partCode', 'model.partSpec']
				this.$refs.form.resetFields()
				this.$refs.form.clearValidate()
				setTimeout(() => {
					this.$refs.form.clearValidate(validateList)
				}, 10)
			},
			// 查询
			submitBtn() {
				queryPageMap({
					page: 1,
					limit: 5000,
					partName: this.model.partName,
					partCode: this.model.partCode,
					partSpec: this.model.partSpec,
				}).then((res) => {
				console.log(res)
					uni.$u.toast(res.message)
					this.$store.commit('inventoryQueryInfoList', res.data)
					uni.navigateTo({
						url: './info'
					})
				}).catch((res) => {
					uni.$u.toast(res.message)
				});
			},
		}
	}
</script>
<style lang="scss" scoped>
	.formList {
		background-color: #fff;
		margin: 10px;
		padding: 10px 10px 20px 10px;
		width: calc(100%-40px);
		height: 100%;
		border-radius: 4px;
	}
</style>
